#include "informationwidget.h"

#include <coreplugin/coreconstants.h>

#include <QtGui/QLayout>
#include <QtGui/QLabel>
#include <QtGui/QToolButton>


// This styled after after coreplugin EditorView's information widget
InformationWidget::InformationWidget(QWidget *parent) :
    QWidget(parent)
{
    m_base = new QFrame(this);
    QVBoxLayout *tl = new QVBoxLayout(this);
    tl->setSpacing(0);
    tl->setMargin(0);

    QPalette pal = m_base->palette();
    pal.setColor(QPalette::Window, QColor(255, 255, 225));
    pal.setColor(QPalette::WindowText, Qt::black);

    m_base->setPalette(pal);
    m_base->setFrameStyle(QFrame::Panel | QFrame::Raised);
    m_base->setLineWidth(1);
    m_base->setAutoFillBackground(true);

    QHBoxLayout *hbox = new QHBoxLayout(m_base);
    hbox->setMargin(2);
    m_infoLabel = new QLabel("Placeholder");
    m_infoLabel->setWordWrap(true);
    hbox->addWidget(m_infoLabel);

    m_infoButton = new QToolButton;
    m_infoButton->setText(tr("Placeholder"));
    hbox->addWidget(m_infoButton);

    m_infoCloseButton = new QToolButton;
    m_infoCloseButton->setAutoRaise(true);
    m_infoCloseButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_CLEAR)));
    m_infoCloseButton->setToolTip(tr("Close"));

    hbox->addWidget(m_infoCloseButton);

    hide();
    tl->addWidget(m_base);

}

void InformationWidget::display(const QString &infoText, const QString &buttonText,
                                QObject *object, const char *buttonPressMember,
                                const char *cancelButtonPressMember)
{
    m_infoLabel->setText(infoText);

    m_infoButton->disconnect();
    if (!buttonText.isEmpty()) {
        m_infoButton->setText(buttonText);
        m_infoButton->setVisible(true);
        if (object && buttonPressMember)
            connect(m_infoButton, SIGNAL(clicked()), object, buttonPressMember);
    } else {
        m_infoButton->setVisible(false);
    }

    m_infoCloseButton->disconnect();
    if (object && cancelButtonPressMember)
        connect(m_infoCloseButton, SIGNAL(clicked()), object, cancelButtonPressMember);
    connect(m_infoCloseButton, SIGNAL(clicked()), this, SLOT(hide()));

    show();
}
